package no.uib.hplims.views.peptides;

import org.vaadin.appfoundation.persistence.facade.FacadeFactory;
import no.uib.hplims.models.Peptide;
import no.uib.hplims.models.peptideinformation.PeptideInformation;
import no.uib.hplims.tools.events.UpdatePeptideInformationListener;

import com.vaadin.ui.Label;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.Runo;

public class PeptideInformationView extends VerticalLayout {

	private static final long serialVersionUID = 8769898298439063879L;

	private Peptide peptide = null;
	private PeptideInformation peptideInformation = null;
	private TabSheet tabs = new TabSheet();

	public PeptideInformationView(Peptide p, UpdatePeptideInformationListener listener) {
		
		setSizeFull();
		
		peptide = p;
		peptideInformation = FacadeFactory.getFacade().find(
				PeptideInformation.class, p.getPeptideInformationID());

		init();

		if (peptideInformation == null) {
			peptideInformation = new PeptideInformation();
			FacadeFactory.getFacade().store(peptideInformation);

			peptide.setPeptideInformationID(peptideInformation.getId());
			FacadeFactory.getFacade().store(peptide);
		}
		
		GeneralPeptideInformationView piw = new GeneralPeptideInformationView(peptide);
		piw.addListener(listener);
		CommentView cv = new CommentView(peptideInformation);
		
		DualView dv = new DualView("General", piw, cv);
		tabs.addTab(dv);
		
		//tabs.addTab(piw);

		TransitionView tv = new TransitionView(peptideInformation.getTransitions(),
				peptideInformation, peptide);
		tv.addListener(listener);
		tabs.addTab(tv);
		tabs.addTab(new StorageView(peptideInformation.getStorageInfo(),
				peptideInformation));
		tabs.addTab(new ResponseCurveView(peptideInformation
				.getResponseCurves(), peptideInformation));
		//tabs.addTab(new CommentView(peptideInformation));
		tabs.setStyleName(Runo.TABSHEET_SMALL);

		addComponent(tabs);

	}

	private void init() {
		setMargin(true, false, false, false);
		setSpacing(true);
		setSizeFull();

		Label header = new Label("Peptide information: "
				+ peptide.getPeptideName());
		header.setStyleName(Runo.LABEL_H2);

		addComponent(header);
	}
}
